package com.omd.client.rel.handle;

import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.omd.client.rel.ReleaseClient;
import com.system.comm.utils.FrameMapUtil;
import com.system.handler.BaseHandle;
import com.system.handler.model.ResponseCode;
import com.system.handler.model.ResponseFrame;

/**
 * app配置的处理类
 * @author yuejing
 * @date 2016年1月29日 下午9:31:59
 * @version V1.0.0
 */
@Component
public class ProjectHandle implements BaseHandle {

	private final static Logger LOGGER = Logger.getLogger(ProjectHandle.class);

	/**
	 * 发布项目
	 * @param map
	 * @return
	 */
	public ResponseFrame release(Map<String, Object> map) {
		try {
			ResponseFrame frame = new ResponseFrame();
			/*
			FrameMapUtil.getString(map, "code"),
			FrameMapUtil.getString(map, "name")*/
			Integer prjId = FrameMapUtil.getInteger(map, "prjId");
			Integer container = FrameMapUtil.getInteger(map, "container");
			String shellScript = FrameMapUtil.getString(map, "shellScript");
			String pathUrl = FrameMapUtil.getString(map, "pathUrl");
			//版本号
			String version = FrameMapUtil.getString(map, "version");
			//发布项目
			ReleaseClient client = new ReleaseClient();
			client.release(prjId, version, container, shellScript, pathUrl);
			
			frame.setCode(ResponseCode.SUCC.getCode());
			return frame;
		} catch (Exception e) {
			LOGGER.error("处理业务异常: " + e.getMessage(), e);
			return new ResponseFrame(ResponseCode.SERVER_ERROR);
		}
	}
}